package com.tsll.service.impl;

import com.tsll.dao.RoleMapper;
import com.tsll.entity.Role;
import com.tsll.service.RoleService;
import com.tsll.vo.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleMapper roleMapper;
    public Result findAll(Integer current,Integer pageSize) {
        PageHelper.startPage(current,pageSize);
        List<Role> roles = roleMapper.selectAll();
        return new Result(200,"查询所有角色",new PageInfo<Role>(roles));
    }

    public Result updateStatus(Integer roleId, Integer status) {
        Integer row = roleMapper.updateStatus(roleId, status);
        if(row==1){
            return new Result(200,"修改状态成功",null);
        }
        return new Result(500,"修改状态失败",null);
    }

    @Override
    public Result deleteAll(Integer roleId) {
        int i = roleMapper.deleteByPrimaryKey(roleId);
        return new Result(200,"删除成功",i);
    }

    @Override
    public Result selectByPrimaryKey(Integer id) {
        Result role = roleMapper.selectByPrimaryKey(id);
        if (role != null) {
            return new Result(200, "查询左侧菜单成功", role);
        } else {
            return new Result(404, "未找到对应部门", null);
        }
    }

    @Override
    public Result selectAll() {
        List<Role> roles = roleMapper.selectAll();

        return new Result(200,"查询角色成功",roles) ;
    }

    @Override
    public Result selectByDept(Integer deptid) {
        List<Role> roles = roleMapper.selectByDeptid(deptid);
        return new Result(200,"查询成功",roles);
    }

    @Override
    public Result update(Role role) {
        int update = roleMapper.update(role);
        return new Result(200,"修改成功",update);
    }

    @Override
    public Result insertAll(Role role) {
        int i = roleMapper.insertSelective(role);
        return new Result(200,"添加成功",i);
    }




}
